package main

import (
	"fmt"
	"time"
)

func main()  {
	chg := make(chan int)
	quit := make(chan bool)


	go func() {
		for {
			select {
			case num := <- chg :
				fmt.Println(num)
			//3秒后超时
			case <-time.After(3 * time.Second):
				fmt.Println("超时")
				quit <- true
			}
		}
	}()

	for i := 0; i < 2; i++ {
		chg <- i
	}

	<- quit
	fmt.Println("程序结束")
}

